home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / misc / borlan32 / fixup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  3.2 KB  |  149 lines

  1.  
  2. //----------------------------------------------------------------------//
  3. // Program to extract stub32.exe and to fix 32rtm.exe                            //
  4. //----------------------------------------------------------------------//
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <string.h>
  10.               
  11.  
  12. // function prototypes
  13. int createstub32(void);
  14. int patch32rtm(void);
  15.  
  16. //----------------------------------------------------------------------//
  17. // Function:        void main(void)                                                    //
  18. //    Description:    entry point to program                                            //
  19. // Parameters:        .                                                                        //
  20. // Returns:            .                                                                        //
  21. //----------------------------------------------------------------------//
  22. void main(void)
  23. {
  24.     if (createstub32())
  25.         exit(1);
  26.  
  27.     exit(patch32rtm());
  28.  
  29. }
  30.  
  31. //----------------------------------------------------------------------//
  32. // Function:        void createstub32(void)                                            //
  33. //    Description:    creates file stub32.exe from tlib.exe                        //
  34. // Parameters:        .                                                                        //
  35. // Returns:            error number                                                        //
  36. //----------------------------------------------------------------------//
  37. int createstub32(void)
  38. {
  39.  
  40.     FILE *infile;
  41.     FILE *outfile;
  42.     int  error;
  43.     char *tbuff;
  44.  
  45.     tbuff = (char *)malloc(2048);
  46.     if (tbuff == NULL)
  47.         {
  48.         printf("Couldn't allocate 2048 bytes?\n");
  49.         return(1);
  50.         }
  51.  
  52.     infile = fopen("tlib.exe", "rb");
  53.     if (infile == NULL)
  54.         {
  55.         printf("Can't find tlib.exe\n");
  56.         return(2);
  57.         }
  58.  
  59.     error = fread(tbuff, 1, 2048, infile);
  60.     fclose(infile);
  61.     if (error != 2048)
  62.         {
  63.         printf("Couldn't read from file tlib.exe\n");
  64.         free(tbuff);
  65.         return(3);
  66.         }
  67.  
  68.     if (strncmp(&tbuff[0x200], "32STUB", 6))
  69.         {
  70.         printf("Doesn't seem to be right file.\n");
  71.         free(tbuff);
  72.         return(5);
  73.         }
  74.  
  75.     outfile = fopen("stub32.exe", "w+b");
  76.     error = fwrite(tbuff, 1, 2048, outfile);
  77.     fclose(outfile);
  78.  
  79.     free(tbuff);
  80.     if (error != 2048)
  81.         {
  82.         printf("Couldn't write to file stub32.exe\n");
  83.         return(4);
  84.         }
  85.  
  86.     return(0);
  87.  
  88. }
  89.  
  90.  
  91. //----------------------------------------------------------------------//
  92. // Function:        void patch32rtm(void)                                            //
  93. //    Description:    patch the 32rtm.exe file                                        //
  94. // Parameters:        .                                                                        //
  95. // Returns:            error number                                                        //
  96. //----------------------------------------------------------------------//
  97. int patch32rtm(void)
  98. {
  99.  
  100.  
  101.     FILE *infile;
  102.     unsigned short chkword;
  103.     int error;
  104.  
  105.     infile = fopen("32rtm.exe", "r+b");
  106.     if (infile == NULL)
  107.         {
  108.         printf("Couldn't open file 32rtm.exe\n");
  109.         return(1);
  110.         }
  111.  
  112.     fseek(infile, 43590L, SEEK_SET);
  113.     error = fread(&chkword, 1, 2, infile);
  114.     if (error != 2)
  115.         {
  116.         printf("unable to read from 32rtm.exe\n");
  117.         fclose(infile);
  118.         return(2);
  119.         }
  120.  
  121.     if (chkword == 0xc031)        // reversed bytes
  122.         {
  123.         printf("File 32rtm.exe is already patched\n");
  124.         fclose(infile);
  125.         return(3);
  126.         }
  127.  
  128.     if (chkword != 0xc23b)        // reversed bytes
  129.         {
  130.         printf("32rtm.exe doesn't seem to be the right file.\n");
  131.         fclose(infile);
  132.         return(4);
  133.         }
  134.  
  135.     chkword = 0xc031;
  136.  
  137.     fseek(infile, 43590L, SEEK_SET);
  138.     error = fwrite(&chkword, 1, 2, infile);
  139.     fclose(infile);
  140.     if (error != 2)
  141.         {
  142.         printf("unable to write to 32rtm.exe\n");
  143.         return(2);
  144.         }
  145.  
  146.     return(0);
  147.  
  148. }
  149.